<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\logic;
use Think\Db;


/**
 * 友情链接逻辑
 */
class Composeselect extends AdminBase
{
    
    // /**
    //  * 获取友情链接列表
    //  */
    // public function getBlogrollList($where = [], $field = true, $order = '', $paginate = 0)
    // {
        
    //     return $this->modelBlogroll->getList($where, $field, $order, $paginate);
    // }
    
    
    public function setcomposeSelect($data = [])
    {
        $value = session('member_info');
        // $validate_result = $this->validateBlogroll->scene('edit')->check($data);
        
        // if (!$validate_result) {
            
        //     return [RESULT_ERROR, $this->validateBlogroll->getError()];
        // }
        // sf($data);
        // $result = $this->modelClassCompose->getInfo($data['co_id'],true


        // $a = Db::table('ob_class_compose')->where('cc_userid',$value['id'])->select();
        Db::table('ob_class_compose')->where('cc_userid', 1)->update(['cc_choice' => '1','update_time' => time()]);
        // && $classarr[sizeof($classarr)-1]['cc_choice']==0
            // if(sizeof($classarr)>0 ){
                // 修改
                // for ($x=0; $x<sizeof($classarr); $x++) {
                    // sf($classarr[$x]['cc_id']);
                //    $data["cc_id"]=$classarr[$x]["cc_id"];
                //    $data["cc_choice"]=1;
                //    $this->modelClassCompose->setInfo($data);
                   
                // } 
            // }else{
                // $data["cc_userid"]=$value["id"];
                // $data["cc_composeid"]=$data["co_id"];
                // $result = $this->modelClassCompose->setInfo($data);
            // }

            $url = url('compose_edit');
            $data["cc_userid"]=$value["id"];
            $data["cc_composeid"]=$data["co_id"];
            
            $result = $this->modelClassCompose->setInfo($data);
       
        
         return $result ? [RESULT_SUCCESS, $url] : [RESULT_ERROR, $this->modelClassCompose->getError()];

    }

    public function fenban($where = [], $field = true, $order = '', $paginate = 0)
    {
     $kaishishu = 0;
     $lastshu=0;
     for($x=9; $x<=19; $x++){
        $dangqiannianjishus=1;
        $d = $this->modelClassCompose->getList(['cc_composeid'=>$x],$field,$order,$paginate);
        $count = sizeof($d);
        $banshu = $count/45;
        $shengyurenshu = $count%45;
        if ($shengyurenshu>30&&$shengyurenshu!=0) {
            $banshu++;
            $dangqiannianjishus = $banshu;
        }
        $lastshu = $dangqiannianjishus;
       $banji=0;
        for ($kaishishu1=$kaishishu; $kaishishu1 <$lastshu ; $kaishishu1++) { 
            $this->logicBan->banEdit(['name'=> $kaishishu1]);
            $banji = $kaishishu1;
        }
        $kaishishu = $banji;
        for ($kaishishu=0; $kaishishu <$dangqiannianjishus ; $kaishishu++) { 
            Db::table('ob_class_compose')->where('cc_composeid', $x)->update(['cc_classid' => $kaishishu,'update_time' => time()]);
            // $this->logicComposeselect->classComposeEdit(['cc_composeid'=>$x,'cc_classid' => $kaishishu]);
        }   
        
    }
     // $url = url('composeselect_list');
     // sf($url);
     //     return true ? [RESULT_SUCCESS, '操作成功', $url] : [RESULT_ERROR, $this->modelClassCompose->getError()];   
}




 public function classComposeEdit($data = [])
    {
        sf($data);
            
        $validate_result = $this->validateBan->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateBan->getError()];
        }
        
        $url = url('composeselect_list');
        
        $result = $this->modelClassCompose->setInfo($data);
        
        $handle_text = empty($data['cc_composeid']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, '班级组合选择' . $handle_text . '，cc_classid：' . $data['cc_classid']);
        
        return $result ? [RESULT_SUCCESS, '操作成功', $url] : [RESULT_ERROR, $this->modelClassCompose->getError()];
    }



    /**
     * 获取友情链接信息
     */
    public function getBlogrollInfo($where = [], $field = true)
    {
        
        return $this->modelBlogroll->getInfo($where, $field);
    }
    
    /**
     * 友情链接删除
     */
    public function blogrollDel($where = [])
    {
        
        $result = $this->modelBlogroll->deleteInfo($where);
        
        $result && action_log('删除', '友情链接删除' . '，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '删除成功'] : [RESULT_ERROR, $this->modelBlogroll->getError()];
    }

      /**
     * 获取文章列表搜索条件
     */
    public function getWhere($uid)
    {
        
        $where = [];
       
        !empty($uid) && $where['cc_userid'] = ['like', '%'.$uid.'%'];
        
        return $where;
    }
}
<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\logic;
use Think\Db;


/**
 * 友情链接逻辑
 */
class Composeselect extends AdminBase
{
    
    // /**
    //  * 获取友情链接列表
    //  */
    // public function getBlogrollList($where = [], $field = true, $order = '', $paginate = 0)
    // {
        
    //     return $this->modelBlogroll->getList($where, $field, $order, $paginate);
    // }
    
    
    public function setcomposeSelect($data = [])
    {
        $value = session('member_info');
      
        $classone = Db::table('ob_class_compose')->where('cc_userid', $value['id'])->limit(1)->order("cc_id desc")->select();
        if(sizeof($classone)>0){
            Db::table('ob_class_compose')->where('cc_id', $classone[0]['cc_id'])->update(['cc_choice' => '1','update_time' => time()]);
        }
            $url = url('compose_edit');
            $data["cc_userid"]=$value["id"];
            $data["cc_composeid"]=$data["co_id"];
            $result = $this->modelClassCompose->setInfo($data);
         return $result ? [RESULT_SUCCESS, $url] : [RESULT_ERROR, $this->modelClassCompose->getError()];

    }

    public function fenban()
    {
     for($x=9; $x<=19; $x++){
        $d = $this->modelClassCompose->getInfo($x, true);
        sf($d);
    }   
        
    }

    /**
     * 获取友情链接信息
     */
    public function getBlogrollInfo($where = [], $field = true)
    {
        
        return $this->modelBlogroll->getInfo($where, $field);
    }
    
    /**
     * 友情链接删除
     */
    public function blogrollDel($where = [])
    {
        
        $result = $this->modelBlogroll->deleteInfo($where);
        
        $result && action_log('删除', '友情链接删除' . '，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '删除成功'] : [RESULT_ERROR, $this->modelBlogroll->getError()];
    }

      /**
     * 获取文章列表搜索条件
     */
    public function getWhere($uid)
    {
        
        $where = [];
       
        !empty($uid) && $where['cc_userid'] = ['like', '%'.$uid.'%'];
        
        return $where;
    }
}
